﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RZRotateChameleon : MonoBehaviour
{
    public GrapplingTongue grappling;

    private Quaternion desiredRotation;
    private float rotationSpeed = 5f;

    private void Update ()
    {

        //if (!grappling.IsGrapping ())
        //{
        //    desiredRotation = transform.parent.rotation;
        //}
        //else
        //{
        //    desiredRotation = Quaternion.LookRotation (grappling.GetGrappingPoint () - transform.position);
        //}

            //transform.rotation = Quaternion.Lerp (transform.rotation, desiredRotation, Time.deltaTime * rotationSpeed);
    }

    void LookAt2D (Vector3 target)
    {
        Vector3 dir = target - transform.position;
        Debug.DrawRay (transform.position, target, Color.red, 10f);
        float angle = Mathf.Atan2 (dir.y, dir.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward);
    }
}
